package com.lagou.dao;

import com.lagou.pojo.Novel;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;

@Mapper
@Component
public interface NovelDao {

    /**
     * 添加
     * */
    @Insert("insert into novel(id,title,author,pic,content) values(#{id},#{title},#{author},#{pic},#{content})")
    @Options(useGeneratedKeys = true, keyProperty = "id",keyColumn = "id")
    int insertNovel(Novel novel);

    /**
     * 查询
     * */
    @Select({"select * from novel where id = #{id}"})
    Novel findNovelById(@Param("id") Long id);

    /**
     * 分页查询
     * */
    @Select("SELECT * FROM novel LIMIT #{offset}, #{size}")
    List<Novel> findNovels(@Param("offset") Long offset, @Param("size") Integer size);

    /**
     * 小说统计
     * */
    @Select("SELECT COUNT(1) FROM novel")
    Long count();
}
